- name: check/create instance
  hosts: hubs-dev.fedorainfracloud.org
  gather_facts: False

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - /srv/private/ansible/vars.yml
   - /srv/web/infra/ansible/vars/fedora-cloud.yml
   - /srv/private/ansible/files/openstack/passwords.yml

  tasks:
  - import_tasks: "{{ tasks_path }}/persistent_cloud.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"


- name: setup all the things
  hosts: hubs-dev.fedorainfracloud.org
  gather_facts: True
  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - /srv/private/ansible/vars.yml
   - /srv/private/ansible/files/openstack/passwords.yml
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml


  pre_tasks:
  - import_tasks: "{{ tasks_path }}/cloud_setup_basic.yml"

  - name: set hostname (required by some services, at least postfix need it)
    hostname: name="{{inventory_hostname}}"

  - import_tasks: "{{ tasks_path }}/yumrepos.yml"

  - dnf: name={{item}} state=present
    with_items:
    - git

  - name: create the code directory
    file: dest=/srv/hubs state=directory owner=fedora group=fedora

  - name: git clone the code
    git: repo=https://pagure.io/fedora-hubs.git
         dest=/srv/hubs/fedora-hubs
         version=develop
    become_user: fedora
    #ignore_errors: true


  roles:
  - basessh
  - certbot

  - role: hubs
    main_user: fedora
    hubs_url_hostname: hubs-dev.fedorainfracloud.org
    hubs_secret_key: demotestinghubsmachine
    hubs_db_type: sqlite
    hubs_dev_mode: false
    hubs_ssl_cert: /etc/letsencrypt/live/hubs-dev.fedorainfracloud.org/cert.pem
    hubs_ssl_key: /etc/letsencrypt/live/hubs-dev.fedorainfracloud.org/privkey.pem


  tasks:
  - dnf: name={{item}} state=present
    with_items:
    - htop
    - tmux
    - vim

  - name: add more hubs workers
    service: name={{item}} enabled=yes state=started
    with_items:
    - hubs-triage@3
    - hubs-triage@4
    - hubs-worker@3
    - hubs-worker@4
